﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.IO;

namespace TouchUmlUI
{
    public class HoverButton : Image
    {

        BitmapImage sourceNormal;
        BitmapImage sourceHover;
        int width;
        int height;
        Cursor oldCursor;

        public double getPositionX()
        {
            return Canvas.GetLeft(this);
        }

        public double getPositionY()
        {
            return Canvas.GetTop(this);
        }


        public void setCanvasPosition(double px, double py)
        {
            Canvas.SetLeft(this, px);
            Canvas.SetTop(this, py);
        }

        public void setInkCanvasPosition(double px, double py)
        {
            InkCanvas.SetLeft(this, px);
            InkCanvas.SetTop(this, py);
        }

        public void mouseEnter(object sender, RoutedEventArgs e)
        {
            oldCursor = this.Cursor;
            this.Cursor = Cursors.Hand;
            this.Source = sourceHover;
        }

        public void mouseLeave(object sender, RoutedEventArgs e)
        {
            this.Cursor = oldCursor;
            this.Source = sourceNormal;
        }

        public void addClickHandler(MouseButtonEventHandler handler)
        {
            this.MouseDown += handler;
        }

        public HoverButton(String normalGfx, String hoverGfx, int width, int height)
        {            
            sourceNormal = new BitmapImage();
            sourceNormal.BeginInit();
            sourceNormal.UriSource = new Uri(normalGfx, UriKind.Relative);
            sourceNormal.EndInit();
            sourceHover = new BitmapImage();
            sourceHover.BeginInit();
            sourceHover.UriSource = new Uri(hoverGfx, UriKind.Relative);
            sourceHover.EndInit();
            this.Width = width;
            this.Height = height;
            this.Source = sourceNormal;
            this.Stretch = Stretch.Fill;
            this.MouseEnter += mouseEnter;
            this.MouseLeave += mouseLeave;            
        }
    }
}
